#!/usr/bin/perl

require "./accounts.pl";
&ReadParse();

my ($username, $uid, $error_msg, %user);

$error_msg = "";

if($in{"username"})
{
	$username = $in{"username"};
}
else
{
	$error_msg = $text{'error_msg_no_username'};
}

unless($error_msg)
{
	$uid = &local_user_exist($username);
	if($uid < 0)
	{
		$error_msg = $text{'error_msg_user_not_exist_local'};
		$logminor= $text{'module_name'};
		$logpriority=$text{'naslog_warning'};
		$event = $text{'accounts_naslog_event_delete_fail_uname_not_exist'};
		$formatstr = sprintf $text{'accounts_naslog_delete_fail_uname_not_exist'}, $username;
	}
}


if($error_msg)
{
#	&header($text{'index_title'}, "", undef, 0, 1);

#	print "<p>", $error_msg;
	if($event)
	{
		&nas_syslog($logminor, $logpriority, $event, $formatstr);
	}
	&error($error_msg);
	&error_setup($text{'error_title_delete_user'});

#	&footer("/accounts/", $text{'index'});
}
else
{
	&delete_user($username);
	$logminor= $text{'module_name'};
	$logpriority=$text{'naslog_info'};
	$event = $text{'accounts_naslog_event_delete_success'};
	$formatstr = sprintf $text{'accounts_naslog_delete_success'}, $username;
	&nas_syslog($logminor, $logpriority, $event, $formatstr);	
	&redirect("/usermin/choose.cgi");

}
